package com.hava.contentsale.service.impl;

import com.hava.contentsale.dao.AccountVODao;
import com.hava.contentsale.meta.AccountVO;
import com.hava.contentsale.meta.UserVO;
import com.hava.contentsale.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * Created by yanfa on 2016/11/20.
 */
@Service
public class AccountServiceImpl implements AccountService {

    @Autowired
    AccountVODao accountVODao;

    //查询卖家的账务列表，并返回
    @Override
    public List<AccountVO> findAll(UserVO userVO) {
        List<AccountVO> accountVOList = this.accountVODao.findAllByUser(userVO.getId());

        for(int index=0;index < accountVOList.size();index++)
            accountVOList.set(index,divide(accountVOList.get(index)));

        return accountVOList;
    }

    //由于数据库导致的price数据需要除以100
    private static AccountVO divide(AccountVO accountVO)
    {
        if(accountVO.getBuyPrice() != null)
            accountVO.setBuyPrice(accountVO.getBuyPrice().divide(new BigDecimal(100)));
        return accountVO;
    }
}
